package com.breeze.blockchain.controller.admin.form.role;

import static com.breeze.blockchain.mybatis.entity.table.RoleTable.ROLE;

import com.breeze.blockchain.mybatis.entity.RoleDo;
import com.breeze.components.mybatis.page.AbstractPageQuery;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 角色列表
 *
 * @author breeze
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema
public class RolePageForm extends AbstractPageQuery<RoleDo> {

  @Schema(title = "角色ids")
  List<Long> ids;

  @Schema(title = "角色名称")
  String name;

  @Schema(title = "角色描述")
  String description;

  @Override
  public QueryWrapper toQueryWrapper() {
    return super.toQueryWrapper()
        .where(
            ROLE.ID
                .in(getIds(), If::isNotEmpty)
                .and(ROLE.NAME.like(getName(), If::hasText))
                .and(ROLE.DESCRIPTION.like(getDescription(), If::hasText)))
        .orderBy(ROLE.ID.desc());
  }
}
